package top.anydata.lifeofcode.lifesystem.dao.sys.user;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import top.anydata.lifeofcode.lifesystem.entity.sys.user.SysAuthUserEntity;

import java.util.Optional;

/**
 * 功能描述:
 *
 * @author <a href="mailto:caingao@anydata.top">CainGao</a>
 * @version V_1.0
 * @date 2023/8/31 5:45 PM
 */
@Repository
public interface ISysAuthUserRepository extends JpaRepository<SysAuthUserEntity,Integer> {

        @Query("SELECT u FROM SysAuthUserEntity u WHERE u.isDeleted <> 1")
        Page<SysAuthUserEntity> findAllNotDeleted(Pageable pageable);

        Optional<SysAuthUserEntity> findByUsername(String username);

        Optional<SysAuthUserEntity> findByEmail(String email);

        @Override
        @Modifying
        @Query("update SysAuthUserEntity s set s.isDeleted = 1 where s.id = ?1")
        void deleteById(Integer id);

        @Modifying
        @Query("update SysAuthUserEntity s set s.isBan = 1 where s.id = ?1")
        void banUserById(Integer id);

        @Modifying
        @Query("update SysAuthUserEntity s set s.isBan = 0 where s.id = ?1")
        void unBanUserById(Integer id);

}
